package main.manager
{
	import com.adobe.fileformats.vcard.Address;
	import com.standlibrary.global.Global;
	
	import flash.display.Sprite;
	
	import main.module.castle.InnerSence;
	import main.module.castle.OuterSence;

	/**
	 * render layer
	 */
	public class SenceManger
	{
		private static var myinstance:SenceManger = new SenceManger();
		
		private var renderLayer:Sprite;
		private var innerSence:InnerSence;
		private var outerSence:OuterSence;
		private var flag:Boolean=true; //true,内部  false,外部
		
		public function SenceManger()
		{
			if(myinstance != null)
				throw new Error("single instance");
		}
		
		public static function get instance():SenceManger
		{
			return myinstance;
		}
		
		/**
		 * 设置ui层
		 */
		public function set main(_sprite:Sprite):void
		{
			renderLayer = _sprite;
		}
		
		/**
		 * 城堡内部
		 */
		private function intoInner():void
		{
			if(outerSence != null && renderLayer.contains(outerSence))renderLayer.removeChild(outerSence);
			
			if(innerSence == null){
				innerSence = new InnerSence();
				innerSence.x = (Global.STAGE_WIDTH - innerSence.width)/2;
				innerSence.y = (Global.STAGE_HEIGHT - innerSence.height)/2;
			}
			renderLayer.addChild(innerSence);
			
			flag = !flag;
		}
		
		/**
		 * 城堡外观
		 */
		private function castleOuter():void
		{
			if(innerSence != null && renderLayer.contains(innerSence))renderLayer.removeChild(innerSence);
			
			if(outerSence == null){
				outerSence = new OuterSence();
				outerSence.x = (Global.STAGE_WIDTH - outerSence.width)/2;
				outerSence.y = (Global.STAGE_HEIGHT - outerSence.height)/2;
			}
			
			renderLayer.addChild(outerSence);
			
			flag = !flag;
		}
		
		public function changeSence():void{
			flag ? intoInner() : castleOuter();
		}
		
	}
}